/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package simhya;

import simhya.gui.*;
import java.awt.EventQueue;
import org.sbml.jsbml.*;



/**
 *
 * @author Luca
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        boolean test = false;
        if (test) 
            test();
        else {
            CommandPromptInteractor interactor;
            interactor = new CommandPromptInteractor();
            EventQueue.invokeLater(interactor);
        }
    }
    
    
    public static void test() {
        
        simhya.matheval.Evaluator e = new simhya.matheval.Evaluator();
        e.addVariable("X", 4.0);
        e.addVariable("Y", 2.0);
        e.addConstant("k", 1.5);
        simhya.matheval.Expression exp = null,exp1,exp2,exp3;
        
        try {
            exp = e.parseExpression("X == 1");            
            e.addExpressionVariable("H", exp);
            e.parseExpression("fun(A,B) = A >= B || k < 1");
            exp1 = e.parseExpression("if(H,fun(X,Y),X>0) && Y != 1");
            
            System.out.println(exp1.toJavaClass());
            simhya.matheval.CompiledExpression ce = exp1.compileExpression();
            
            
            
            
            
//            int reps=1000000;
//            long time = System.nanoTime();
//            for (int i=0;i<reps;i++)
//                exp1.computeValue();
//            time = System.nanoTime() - time;
//            double nc = (double)time/1000000000;
//            System.out.println("Non compiled: " + nc);
//            time = System.nanoTime();
//            for (int i=0;i<reps;i++)
//                ce.evaluate();
//            time = System.nanoTime() - time;
//            double c = (double)time/1000000000;
//            System.out.println("Compiled: " + c);
//            System.out.println("Speedup: " + nc/c);
        } catch (Exception ex) {
            ex.printStackTrace();
        } catch (Error err) {
            err.printStackTrace();
        }
    }
    
    private static void contains(simhya.matheval.Expression exp, String symbol) {
        if (exp.containsSymbol(symbol))
                System.out.println(exp.toString() + " contains symbol " + symbol);
        if (exp.containsConstant(symbol))
                System.out.println(exp.toString() + " contains constant " + symbol);
        if (exp.containsGlobalVariable(symbol))
                System.out.println(exp.toString() + " contains global variable " + symbol);
        if (exp.containsExpressionVariable(symbol))
                System.out.println(exp.toString() + " contains expression variable " + symbol);
        if (exp.containsBoundVariable(symbol))
                System.out.println(exp.toString() + " contains bound variable " + symbol);
    }


}